package active.commond.invoker;

import active.commond.concretecommond.ICommond;
import active.commond.concretecommond.NoCommond;

public class RemoteInvoker2 {

    private ICommond[] commondOnArray;
    private ICommond[] commondOffArray;
    private ICommond commondUndo;

    public RemoteInvoker2() {
        commondOnArray = new ICommond[5];
        commondOffArray = new ICommond[5];
        for (int i = 0; i < 5; i++) {
            commondOnArray[i] = new NoCommond();
            commondOffArray[i] = new NoCommond();
        }
        commondUndo = new NoCommond();
    }

    public void setCommond(int index, ICommond commondOn, ICommond commondOff) {
        commondOnArray[index] = commondOn;
        commondOffArray[index] = commondOff;
    }

    public void pressButtonOn(int index) {
        commondOnArray[index].execute();
        commondUndo = commondOnArray[index];
    }

    public void pressButtonOff(int index) {
        commondOffArray[index].execute();
        commondUndo = commondOffArray[index];
    }

    public void undo() {
        commondUndo.undo();
    }

}
